import Taro from "@tarojs/taro";

export const setCache = (key, value) => {
  Taro.setStorageSync(
    key,
    typeof value === "object" ? JSON.stringify(value) : value
  );
};

export const getCache = key => {
  return Taro.getStorageSync(key) ? JSON.parse(Taro.getStorageSync(key)) : {};
};

export const removeCache = key => {
  (getCache(key) || Object.keys(getCache(key)).length > 0) &&
    Taro.removeStorageSync(key);
};
